class Api::NavigationsController < ApplicationController
  before_action :set_navigation, only: [:show, :update, :destroy]

  def index
    @result = {}
    @result[:total] = Navigation.filt(params[:filter]).size
    @result[:data] = Navigation.filt(params[:filter]).sort(params[:sort]).page(params[:page]).per(params[:limit])
    render json: @result
  end

  def show
    render json: @navigation
  end

  def create
    @navigation = Navigation.new(navigation_params)
    if @navigation.save
      render json: { success: true }
    else
      render json: { success: false }
    end
  end

  def update
    @navigation.update(navigation_params)
    render json: { success: true }
  end

  def destroy
    @navigation.destroy
    render json: { success: true }
  end

  private

  def set_navigation
    @navigation = Navigation.find(params[:id])
  end

  def navigation_params
    params.require(:navigation).permit(:text, :module, :template, :icon_cls, :glyph)
  end
end